import { getHtml } from '@/services/mdSsr';
import { Effect, ImmerReducer, Subscription } from 'umi';
export interface MdSsrModelState {
    markdown: string;
    helmet: {
        title: string,
        keywords: string,
        description: string
    }
}
export interface MdSsrModelType {
    namespace: 'mdSsr';
    state: MdSsrModelState;
    effects: {
        query: Effect;
    };
    reducers: {
        // 启用 immer 之后
        save: ImmerReducer<MdSsrModelState>;
    };
    subscriptions: { setup: Subscription };
}
const MdSsrModel: MdSsrModelType = {
    namespace: 'mdSsr',
    state: {
        markdown: '',
        helmet: {
            title: 'lyscms+ 美好生活从亮月网开始',
            keywords: 'code,lyscms+',
            description: '为你方便，为你喝彩'
        }
    },
    effects: {
        *query({ payload }, { call, put }) {
            const response = yield call(getHtml, payload);
            yield put({
                type: 'save',
                payload: response
            });
        },
    },
    reducers: {
        // 启用 immer 之后
        save(state, action) {
            state.markdown = action.payload;
        },
    },
    subscriptions: {
        setup({ dispatch, history }) {
            return history.listen(({ pathname }) => {
                if (pathname === '/') {
                    dispatch({
                        type: 'query',
                    })
                }
            });
        }
    }
};
export default MdSsrModel;